﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Pr0ject0.Models;
using System.Collections;

namespace Pr0ject0.Controllers
{
    [Authorize(Roles="Staffing Expert")]
    public class StaffingExpertController : Controller
    {
        //
        // GET: /StaffingExpert/
        QuestionAnswerDb QA = new QuestionAnswerDb();
        List<KeyValuePair<string, int>> types = new List<KeyValuePair<string, int>>(new KeyValuePair<string, int>[] { new KeyValuePair<string, int>("Multiple Choice", 0), new KeyValuePair<string, int>("True/False", 1), new KeyValuePair<string, int>("Short Essay", 2), new KeyValuePair<string, int>("Long Essay", 3) });
        
        public ActionResult Index()
        {
            Dictionary<int, string> titles = new Dictionary<int, string>(JobTitleDB.GetInstance().jobTitles);
            titles[0] = "General";
            titles.OrderBy(n => n.Key);
            ViewBag.titles = titles;
            return View();
        }

        public ActionResult CreateTitle()
        {
            return View();
        }

        [HttpPost]
        public ActionResult CreateTitle(JobTitleModel jobtitlemodel)
        {          
            JobTitleDB.GetInstance().AddJob(jobtitlemodel);

            int id = -1;

            foreach (JobTitleModel x in JobTitleDB.GetInstance().titleList)
            {
                if (x.titleName == jobtitlemodel.titleName)
                {
                    id = x.title;
                }

            }
            return Redirect("~/StaffingExpert/CreateQuestionnaire/" + id);
        }

        public ActionResult CreateQuestionnaire(int id)
        {
            ViewBag.types = types;
            ViewBag.questionnaire = QA.GetQuestionnaire(new int[] { id }).FindAll(x => x.title == id).Distinct();
            return View(new QuestionModel() { title=id });
        }

        [HttpPost]
        public ActionResult CreateQuestionnaire(FormCollection collection)
        {
            QuestionModel model = new QuestionModel();
            model.question = collection["question"];
            model.answer = collection["answer"];
            model.title = Convert.ToInt32(collection["title"]);
            model.type = Convert.ToInt32(collection["type"]);
            QA.AddQuestion(model);
            return Redirect("~/StaffingExpert/CreateQuestionnaire/" + model.title);
        }

        [HttpPost]
        public ActionResult Done(FormCollection collection)
        {
            QuestionModel model = new QuestionModel();
            model.question = collection["question"];
            model.answer = collection["answer"];
            model.title = Convert.ToInt32(collection["title"]);
            model.type = Convert.ToInt32(collection["type"]);
            QA.AddQuestion(model);
            return RedirectToAction("Index");
        }

    }
}
